﻿namespace Stopwatch.Views
{
    using Microsoft.Phone.Controls;
    using Stopwatch.Controls;
    using Stopwatch.Core;
    using Stopwatch.ViewModels;
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Windows;
    using System.Windows.Controls;

    public partial class MainPage : PhoneApplicationPage
    {
        // 构造函数
        public MainPage()
        {
            InitializeComponent();

            // 将 listbox 控件的数据上下文设置为示例数据
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
            SplitItemsControl.SizeChanged += OnSplitItemsControlSizeChanged;
        }

        // 为 ViewModel 项加载数据
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = new MainContext(this);
        }

        private void OnSplitItemsControlSizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (e.NewSize.Height > SplitItemsControlScrollViewer.Height)
            {
                SplitItemsControlScrollViewer.ScrollToVerticalOffset(e.NewSize.Height - SplitItemsControlScrollViewer.Height);
            }
        }

        private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
        {
        }

        private void HelpOnClick(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/Infomation.xaml", UriKind.Relative));
        }

        private void SettingsOnClick(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/SettingsPage.xaml", UriKind.Relative));
        }

        public Time TimerDuration { get { return timerControl.TimerDuration; } }
    }
}